// #ifdef APP-PLUS
class sheilding {
	maskView = null
	obj = {}
	//扩大区域范围参数
	padding = 0
	constructor(obj) {
		this.obj = {
			top: obj.top + this.padding,
			left: obj.left + this.padding,
			height: obj.height + this.padding,
			width: obj.width + this.padding
		}
	}
	init() {
		let section1 = {
			name: 'section1',
			top: '0px',
			left: '0px',
			height: `${this.obj.top}px`,
			width: '100%'
		};

		let section2 = {
			name: 'section2',
			top: `${this.obj.top+this.obj.height}px`,
			left: '0px',
			height: 'calc(100% -(' + `${this.obj.top+this.obj.height}px` + '))',
			width: '100%'
		};

		let section3 = {
			name: 'section3',
			top: `${this.obj.top}px`,
			left: '0px',
			height: `${this.obj.height}px`,
			width: `${this.obj.left}px`
		};

		let section4 = {
			name: 'section4',
			top: `${this.obj.top}px`,
			left: `${this.obj.left+this.obj.width}px`,
			height: `${this.obj.height}px`,
			width: 'calc(100% -(' + `${this.obj.left+this.obj.width}px` + '))'
		}
		const prms1 = new Promise((resolve, reject) => this.showMask(section1))
		const prms2 = new Promise((resolve, reject) => this.showMask(section2))
		const prms3 = new Promise((resolve, reject) => this.showMask(section3))
		const prms4 = new Promise((resolve, reject) => this.showMask(section4))
		Promise.all([prms1, prms2, prms3, prms4])
	}

	showMask(obj) {
		this.maskView = new plus.nativeObj.View(obj.name, {
			top: obj.top,
			left: obj.left,
			height: obj.height,
			width: obj.width,
		})
		// color: 'rgba(26, 84, 159, 1)' 有颜色
		// color: this.getRandomColor(), //有颜色
		this.maskView.drawRect({
			// color: 'rgba(255, 255, 255, 0.0)', //无色
			color: this.getRandomColor(), //有颜色

		})
		// 设置遮罩块显示内容
		// this.maskView.drawText(obj.name)
		//监听被遮盖区域的点击事件
		this.maskView.addEventListener('click', () => {
			this.clickHandle()
		}, false)
		// 监听被遮盖区域的触摸事件
		this.maskView.addEventListener('touchmove', () => {
			// this.touchmoveHandle()
		}, false)

		this.maskView.show()

	}
	//销毁对象view
	destroyMask(name) {
		plus.nativeObj.View.getViewById(name).hide()
		plus.nativeObj.View.getViewById(name).close()
	}

	clickHandle() {
		console.log('--------------->clickHandle')
	}
	touchmoveHandle() {
		console.log('=========touchmoveHandle')
	}
	//获取随机颜色
	getRandomColor() {
		var r = Math.floor(Math.random() * 256); //随机生成256以内r值
		var g = Math.floor(Math.random() * 256); //随机生成256以内g值
		var b = Math.floor(Math.random() * 256); //随机生成256以内b值
		var alpha = Math.random(); //随机生成1以内a值
		return `rgb(${r},${g},${b},${alpha})`; //返回rgba(r,g,b,a)格式颜色
	}
}


export default sheilding

// #endif